package com.wss.merchant.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.springframework.stereotype.Component;

import java.util.Calendar;

@Component
public class JWTUtil {
    //盐
    private static final String SING = "wss" ;

    public String getToken(Integer userId ,String userName){
        //过期时间
        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.DATE,7);
        //生成Token
        String Token = JWT.create()

                .withClaim("userId", userId)
                .withClaim("userName", userName)
                .withExpiresAt(instance.getTime())
                .sign(Algorithm.HMAC256(SING));

        return Token;
    }
    //验证Token
    public DecodedJWT verifyToken(String token){
        return JWT.require(Algorithm.HMAC256(SING)).build().verify(token);
    }


}